At 07:39 +0300 on 23/04/1999, Chris Bitmead wrote:
> httpd=> select title, summary, time from story t where time IN (select
> max(s.time) from story s GROUP BY s.title);
> ERROR: parser: Subselect has too many or too few fields.
Of course it does. Since you group by a field which is not in the select
list, Postgres adds it silently to the fields to be selected. Thus the
subselect has two fields in each row, not just a single time field.
I think the proper syntax by the standard would be something like:
SELECT title, summary, timeFROM story tWHERE (time, title) IN ( SELECT s.title, max( s.time ) FROM story s GROUP
BYs.title);
But I'm not sure Postgres even supports this format (of comparing against
several fields).
In any case, the best would be to select just one tuple in the subselect
and have it return only the time, by constraining the title. But
syntactically, the above is what you were trying to do.
Anyway, Postgres adds the group field to the query, which the standard
requires and common practice doesn't. I think perhaps after doing the
grouping, Postgres should drop that field, since it wasn't originally
requested.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma